package createdomain;

## This file is part of the Simplemail project.
#  Copyright (c) 2008 the Simplemail Team (see authors).
# 
#  For the full copyright and license information, please view the COPYING
#  file that was distributed with this source code. You can also view the
#  COPYING file online at http://unixforum.org.ua/misc/COPYING.txt
# 
#  @copyright  (c) the authors
#  @author     Dmitriy Shilenko <rtyug@ukr.net>
#  @license    GPLv2 http://unixforum.org.ua/misc/COPYING.txt
#  @package    Panel Mailbox
#  @version    $Id: $

use strict;
use CGI::Carp qw(fatalsToBrowser);
use base 'func';

sub new {
    my $self = shift->SUPER::new(@_);
    $self->dbi_connect if $self->can("dbi_connect");
    return $self;
}

sub return_create_domain {

    my $self = shift;

    my $dd;
    my %he;

    if ( $self->{session}->{name} ne 'Admin' ) {

        my $sth = $self->{dbh}->prepare(
            'SELECT (select count(*) from domain where idnane = ?) AS c_domain,
                                m_domain
                         FROM admin_domain 
                         WHERE idname = ? limit 1
                             '
        );
        $sth->execute( $self->{session}->{user}, $self->{session}->{user} );
        $dd = $sth->fetchrow_hashref();
        $sth->finish();

    }

    if (   ( $dd->{m_domain} != 0 )
        && ( $dd->{m_domain} <= $dd->{c_domain} )
        && ( $self->{session}->{name} ne 'Admin' ) )
    {
        $self->{he}->{DOMAIN_ERROR} = 1;

    }

    return $self;
}

sub templ_hash_domain {
    my $self = shift;

    $self->{session}->{filet} = 'create-domain';
    $self->SUPER::templ_hash(@_);
}

sub DESTROY {
    my $self = shift;
    $self->SUPER::DESTROY if $self->can("SUPER::DESTROY");
}

1;
